/*
 * 
 */
package net.capstone.cra.smartcontroller.filter;

/**
 * The implementation of Low-pass filter.
 */
public class LowPassFilter implements SensorFilter {
	
	/**
	 * The factor of the filter.
	 */
	private final float FACTOR = 0.1f;
	
	/**
	 * The previous input values.
	 * Recorded for filtering.
	 */
	private float[] prev = { 0, 0, 0 };

	/* (non-Javadoc)
	 * @see smartcontroller.filter.Filter#filter(float[])
	 */
	@Override
	public float[] filter(float[] values) {
		float[] result = new float[values.length];

		for (int i = 1; i < values.length; i++) {
			prev[i] = values[i] * FACTOR + prev[i] * (1.0f - FACTOR);
			result[i] = prev[i];
		}

		return result;
	}

}
